﻿// -------------------------------------------------------------------------
//    @FileName         :    NFWelfareMgr.h
//    @Author           :    gaoyi
//    @Date             :    2025-07-26
//    @Email			:    445267987@qq.com
//    @Module           :    NFWelfareMgr
//
// -------------------------------------------------------------------------

#pragma once

#include <NFLogicCommon/NFLogicShmTypeDefines.h>

#include "proto_welfare.nanopb.h"
#include "NFComm/NFObjCommon/NFObjectTemplate.h"
#include "NFLogicCommon/NFWelfareConf.h"
#include "NFServerComm/NFServerCommon/NFServerSyncDataGlobalTemplate.h"

class NFWelfareMgr : public NFServerSyncDataGlobalTemplate<NFWelfareMgr, proto_ff::SSWorldWelfareSyncAllData, EOT_LOGIC_WELFARE_MGR_ID>
{
public:
    NFWelfareMgr();
    ~NFWelfareMgr() override;
    int CreateInit();
    int ResumeInit();
public:
    int Awake() override;
    int AfterObjFromDBLoaded(NF_SERVER_TYPE serverType) override;
    int AfterAppInitFinish() override;
    int OnHandleServerMessage(uint64_t unLinkId, NFDataPackage& packet) override;
public:
    int OnHandleWorldWelfareSyncConf(uint64_t unLinkId, NFDataPackage& packet);
    int OnHandleWorldWelfareSync(uint64_t unLinkId, NFDataPackage& packet);
    int OnHandleWorldWelfareSyncDBData(uint64_t unLinkId, NFDataPackage& packet);
public:
    int ProcessMsgWorldWelfareSyncOpenShowRes(const proto_ff::SSWorldWelfareSyncOpenShowRes* pMsg);
    // world下发的福利配置
    int ProcessMsgWorldWelfareSyncConfRes(const proto_ff::SSWorldWelfareSyncConfRes* pMsg);

    int LoadShowAndOpenIDs(const proto_ff::SSWorldWelfareSyncOpenShowRes* pMsg);

    int ProcessMsgWorldWelfareSyncDBDataRes(const proto_ff::SSWorldWelfareSyncDBDataRes* pMsg);
public:
    int SyncData(const proto_ff::SSWorldWelfareSyncAllData &dbData) override;
private:
    // WorldDBData world唯一数据
    WelfareDBWorldData m_stWorldDBData;
    NFWelfareConf m_Conf;
    // 正在开启/展示的福利
    WelfareOpenShowWorldData m_stWorldOpenShowData;
    // 最后福利展示及开启id 变更的时刻
    uint32_t m_dwLastIDChangeUnixSec;
    // 使用的配置的加载时刻 0还未加载配置
    // 做版本控制用
    // worldsvr 下发配置时带
    uint32_t m_dwConfLoadUnixSec;
    // 使用的最后的配置时刻(来自world)
    // 等gs拉取到的版本>m_dwUseLastConfLoadUnixSec 时，才算拉取成功
    uint32_t m_dwUseLastConfLoadUnixSec;
};
